<!-- treeNode.vue -->
<template>
	<view style="margin: 20rpx;">
		<view :class="['item--list fade-in r',item.is_level!=1&&'pL']" v-for="(item, index) in list" :key="index"
			@click.stop="handleOpenClose(item, index)">
			<view class="item--row  radius">
				<view class="item--title">
					<view class="icon-wrap">
					</view>
					<view class="item--title--text ofhideellipsis " style="color: #fff;">
						<text v-if="item.children!=null">{{ item.label +" （"+(item.children.length)+"）"}}</text>
						<view v-else style="display: flex;">
							<view style="border:#0009ff solid 1px ;background-color: #fff;width: 50rpx;height: 50rpx;"
								class="radius margin-right-sm" @click="ppppp(item)">
								<uni-icons type="checkmarkempty" size="25" style="color: #0009ff;"
									v-if="item.select"></uni-icons>
							</view>
							{{ item.label }}
						</view>

					</view>
				</view>
				<view :class="{'rotate':item.isOpen}">
					<uni-icons type="right" style="color: #fff;" size="24"></uni-icons>
				</view>
			</view>

			<!-- 使用组件本身渲染子项 -->
			<view v-if="item.isOpen && item.children && item.children.length>0">
				<treeItem :list="item.children" @ppppp2="ppppp2">
				</treeItem>
			</view>
		</view>

	</view>
</template>

<script>
	// 引入当前组件
	import treeItem from '../treeNode/treeNode'
	export default {
		name: 'treeItem',
		components: {
			treeItem
		},
		// 接收列表数据
		props: {
			list: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {}
		},
		onLoad() {},
		onShow() {},
		mounted() {},
		methods: {
			// 处理展开或收起
			handleOpenClose(item, index) {
				// 如果不存在isOpen属性就添加该属性。
				if (!item.hasOwnProperty('isOpen')) {
					item.isOpen = false
				}
				item.isOpen = !item.isOpen
				this.$forceUpdate()
			},
			ppppp(e) {

				e.select = !e.select
				this.$emit("ppppp2", e)
			},

			ppppp2(e) {


				this.$emit("ppppp2", e)
			}
		}
	}
</script>

<style scoped lang="scss">
	.pL {
		padding-left: 40rpx;
	}

	.item--list {

		.item--row {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid #f7f7f7;
			padding: 10rpx;
			background-color: #b5b5b5;
			margin-top: 10rpx;

			.item--title {
				display: flex;
				align-items: center;
				font-size: 28rpx;


				.icon-wrap {
					width: 25rpx;
					margin-right: 10rpx;
				}
			}

			.item--btn {
				display: flex;

				.btn {
					margin-left: 40rpx;
					color: #fff;
				}

				.noActive {
					color: #ccc;
				}
			}
		}

	}


	.open__and--close {
		margin-left: 40rpx;
		font-size: 24rpx;
	}

	.rotate {

		transform: rotate(90deg);
		/* 旋转90度 */
		transition: transform 0.5s;
		/* 添加过渡效果 */
	}


	.tree__hover-class {
		background-color: #f7f7f7;
	}

	.fade-in {
		opacity: 0;
		/* 初始透明度为0 */
		transform: translateY(-20px);
		/* 初始位置向上偏移20px */
		animation: fadeInDown .5s forwards;
		/* 动画持续1秒，保持最终状态 */
	}

	@keyframes fadeInDown {
		to {
			opacity: 1;
			/* 最终透明度为1 */
			transform: translateY(0);
			/* 最终位置为原位置 */
		}
	}
</style>